﻿using Taype.Trading.BTC.MtGoxAPIClient;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace MtGoxAPIClient_test
{
    
    
    /// <summary>
    ///This is a test class for MtGoxHelpersTest and is intended
    ///to contain all MtGoxHelpersTest Unit Tests
    ///</summary>
    [TestClass()]
    public class MtGoxHelpersTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for HowManyBTCCanIGet
        ///</summary>
        [TestMethod()]
        public void HowManyBTCCanIGetTest()
        {
            double usdAvailable = 10.45096;
            double price = 6.25000;
            double feeRate = 0.46;
            double expected = 1.66446231; // 1.67215422−0.00769191
            double actual;
            actual = MtGoxHelpers.HowManyBTCCanIGet(usdAvailable, price, feeRate);
            Assert.AreEqual(expected, actual);

            // we also need to test for the case where minimum purchase amount 
        }

        /// <summary>
        ///A test for HowManyBTCDoINeedToGetThisUSD
        ///</summary>
        [TestMethod()]
        public void HowManyBTCDoINeedToGetThisUSDTest()
        {
            double usdTarget = 31.65407; // TODO: Initialize to an appropriate value
            double price = 6.36007; // TODO: Initialize to an appropriate value
            double feeRate = 0.46; // TODO: Initialize to an appropriate value
            double expected = 5; // TODO: Initialize to an appropriate value
            double actual;
            actual = MtGoxHelpers.HowManyBTCDoINeedToGetThisUSD(usdTarget, price, feeRate);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for IsTradeFeasible
        ///</summary>
        [TestMethod()]
        public void IsTradeFeasibleTest()
        {
            // first test bid
            double currentBalanceUSD = 1;
            double currentBalanceBTC = 1;
            double amount = 1;
            double price = 2;
            double feeRate = 0.6;
            MtGoxTradeType tradeType = MtGoxTradeType.bid;
            bool expected = false;
            bool actual;
            actual = MtGoxHelpers.IsTradeFeasible(currentBalanceUSD, currentBalanceBTC, amount, price, feeRate, tradeType);
            Assert.AreEqual(expected, actual);
            // now ask
            tradeType = MtGoxTradeType.ask;
            expected = true;
            actual = MtGoxHelpers.IsTradeFeasible(currentBalanceUSD, currentBalanceBTC, amount, price, feeRate, tradeType);
            Assert.AreEqual(expected, actual);
        }
    }
}
